import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext import search
from google.appengine.ext import db
import json

class MainPage(webapp.RequestHandler):
  def get(self):
    # We use the webapp framework to retrieve the postal_code
    suburb_name = self.request.get('suburb_name')

    self.response.headers['Content-Type'] = 'text/html'
    if not suburb_name:
      self.response.out.write("<p>No suburb_name has been set</p>")
    else:
      # Search the 'PostalCode' Entity based on our postal_code
      query = search.SearchableQuery('PostalCode')
      query.Search(suburb_name)
      for PostalCode in PostalCode.all():
          item = {'suburb' : result['suburb'],
                  'postal_code' : result['postal_code'] }
          postal_codes.append(item)
          self.response.out.write(json.write(postal_codes))

def main():
  application = webapp.WSGIApplication([('/', MainPage)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()